﻿namespace Pub.Class
{
    using System;
    using System.Collections;

    public class WebServiceHelper : Disposable
    {
        private IWebService WebService;
        private Pub.Class.WebServiceEnum WebServiceEnum;

        public WebServiceHelper(Pub.Class.WebServiceEnum WebServiceEnum)
        {
            this.WebServiceEnum = WebServiceEnum;
            this.init();
        }

        public WebServiceHelper(string WebServiceEnum)
        {
            this.WebServiceEnum = WebServiceEnum.ToEnum<Pub.Class.WebServiceEnum>();
            this.init();
        }

        public string Call(string url, string className, string methodName, Hashtable parms)
        {
            return this.WebService.Call(url, className, methodName, parms);
        }

        private void init()
        {
            switch (this.WebServiceEnum)
            {
                case Pub.Class.WebServiceEnum.get:
                    this.WebService = new GetWebService();
                    return;

                case Pub.Class.WebServiceEnum.post:
                    this.WebService = new PostWebService();
                    return;

                case Pub.Class.WebServiceEnum.soap:
                    this.WebService = new SoapWebService();
                    return;

                case Pub.Class.WebServiceEnum.dynamic:
                    this.WebService = new DynamicWebService();
                    return;
            }
            this.WebService = new GetWebService();
        }

        protected override void InternalDispose()
        {
            this.WebService = null;
            base.InternalDispose();
        }
    }
}

